//
//  TJActivationCodeUseRecordController.m
//  BaoDian
//
//  Created by mac on 2024/7/29.
//

#import "TJActivationCodeUseRecordController.h"
#import "TJActivationCodeUseRecordCell.h"
#import "TJEmptyDataHandler.h"

#import "TJUseActivationCodeController.h"
 

@interface TJActivationCodeUseRecordController ()

@property (nonatomic, strong) NSArray *datas;
@property (nonatomic, strong) TJEmptyDataHandler *emptyDataHandler;

@end

@implementation TJActivationCodeUseRecordController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.navigationBar.title = @"使用记录";
    
    [self.tableView registerClass:TJActivationCodeUseRecordCell.class forCellReuseIdentifier:@"TJActivationCodeUseRecordCell"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.rowHeight = 186;
    self.tableView.contentInset = UIEdgeInsetsMake(16, 0, 0, 0);
    self.tableView.contentOffset = CGPointMake(0, -16);
    self.tableView.backgroundColor = self.view.backgroundColor;
    [self.tableView setSectionIndexColor:UIColor.tj_9B9B9BColor];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(KNavBarHight);
        make.left.right.bottom.offset(0);
    }];
    
    _emptyDataHandler = [TJEmptyDataHandler emptyDataHandleWithScrollView:self.tableView configuration:^TJEmptyDataType(TJEmptyDataModel * _Nonnull dataModel) {
        dataModel.text = @"你暂时还没有激活码";
        dataModel.iconName = @"activationCodeEmpty";
        return TJEmptyDataTypeBase;
    }];
    
    [self loadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.datas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    TJActivationCodeUseRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TJActivationCodeUseRecordCell" forIndexPath:indexPath];
    cell.model = self.datas[indexPath.row];
    return cell;
}

- (void)loadData {
   [TJMinePresent loadActiveCodeListWithPageIndex:1 isUse:YES complete:^(NSArray * _Nonnull datas, NSError * _Nullable error) {
       self.emptyDataHandler.canDisplay = YES;
        self.datas = datas;
        [self.tableView reloadData];
   }];
}
 
@end

